/*
 * @Author: your name
 * @Date: 2021-05-31 15:41:02
 * @LastEditTime: 2021-06-10 14:41:23
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \qixin-renewal-pc\src\utils\http.js
 */
import request from '@/utils/request';
import { message } from 'antd';

export async function post(params: { url: string; data: any }) {
  const requestData = request.post(params.url, { data: params.data });
  requestData.then((resJson) => {
    if (resJson.code === 401) {
      const redirectUrl = window.location.href;
      window.location.href = `https://huntian.hzins.com/login?redirectUrl=${redirectUrl}`;
      return;
    }
    if (resJson.code !== 0 || resJson.success !== true) {
      message.error(resJson.msg || '请求出错，请稍后再试');
    }
  });
  return requestData;
}

export async function get(params: { url: string; data: any }) {
  const datas = params.data;
  const requestData = request(params.url, {
    method: 'GET',
    params: { ...datas },
  });
  requestData.then((resJson) => {
    if (resJson.code === 401) {
      const redirectUrl = window.location.href;
      window.location.href = `https://huntian.hzins.com/login?redirectUrl=${redirectUrl}`;
      return;
    }
    if (resJson.code !== 0 || resJson.success !== true) {
      message.error(resJson.msg || '请求出错，请稍后再试');
    }
  });
  return requestData;
}
